/**
 * 角色构造逻辑
 *author:noodles 
 */
package com.gamebase.role
{
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class AvatarUtils
	{
		private static var _instance:AvatarUtils;
		
		public function AvatarUtils()
		{
		}
		
		private static function get instance():AvatarUtils
		{
			if(_instance == null)
				_instance = new AvatarUtils();
			return _instance;
		}
		
		/**
		 *系列化位图数据 
		 * @param fullBmd:	包含各方向的帧矩阵
		 * @param rec:		单帧区域
		 * @return 
		 * 
		 */		
		public static function serializationBMD(fullBmd:BitmapData, rec:Rectangle):Vector.<Vector.<BitmapData>>
		{
			var returnValue:Vector.<Vector.<BitmapData>> = new Vector.<Vector.<BitmapData>>();
			var lineVector:Vector.<BitmapData>;
			var framePerLine:uint = uint(fullBmd.width/rec.width);
			var frameRec:Rectangle = rec.clone();
			var destPoint:Point = new Point(0,0);
			var h:uint = 0;
			var i:uint = 0;
			var bmd:BitmapData;
			
			while(h < fullBmd.height)
			{
				i = 0;
				frameRec.x = 0;
				frameRec.y = h;
				lineVector = new Vector.<BitmapData>();
				while(i<framePerLine)
				{
					bmd = new BitmapData(rec.width, rec.height, true, 0x0);
					bmd.copyPixels(fullBmd, frameRec, destPoint);
					bmd.draw(fullBmd);
					lineVector.push(bmd);
					frameRec.x += frameRec.width;
					i++;
				}
				returnValue.push(lineVector);
				h+=rec.height;
			}
			
			return returnValue;
		}
		
		
	}
	
	
}